﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

/// <summary>
/// Summary description for GroupNewsDAL
/// </summary>
public class GroupNewsDAL : BaseDAL
{
    public DataSet List()
    {
        DataSet ds = new DataSet();

        string query = "select * from MiT_GroupNews where Status != '0'";
        ds = base.RunQuery(query);
        return ds;
    }
    public DataSet Detail(int groupNewsId)
    {
        DataSet ds = new DataSet();

        string query = "select * from MiT_GroupNews where Id = " + groupNewsId.ToString();
        ds = base.RunQuery(query);

        return ds;
    }
    public DataSet UpdateStatusActive(int groupNewsId, int Status)
    {
        DataSet ds = new DataSet();
        string query = string.Format("Update MiT_GroupNews set Status={0} where id={1}; select {1} as Id", Status, groupNewsId);
        ds = base.RunQuery(query);
        return ds;
    }
    public DataSet Update(int groupNewsId, string name, int Status)
    {
        DataSet ds = new DataSet();
        string urlFriendly = URLHelper.URLFriendly(name);
        string query = string.Format("Update MiT_GroupNews set Name=N'{0}', Status={1}, FriendlyURL='{3}' where Id={2}; Select {2} as Id;", name, Status, groupNewsId.ToString(), urlFriendly);
        ds = base.RunQuery(query);

        return ds;
    }
    public DataSet Insert(string name, int Status)
    {
        DataSet ds = new DataSet();
        string urlFriendly = URLHelper.URLFriendly(name);
        string query = string.Format("insert into MiT_GroupNews (Name, Status, FriendlyURL) values (N'{0}', '{1}', '{2}');", name, Status, urlFriendly);
        ds = base.RunQuery(query);

        return ds;
    }
}